<?php

namespace App\Listeners;

use App\Http\Model\Log;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class UserLoginListener
{
    private $log = [];
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        $this->log['ip'] = request()->ip() ?? '127.0.0.1';
        $this->log['time'] = date('Y-m-d H:i:s',time());
        $this->log['type'] = 1;  //日志类型0错误日志，1操作日志
        $this->log['username'] = $event->username;
        $mess = "用户{$event->username}登录了系统";
        $this->log['record'] = $mess;
        Log::create($this->log);
    }
}
